package springbook.config;


import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import springbook.enums.ResultCodeEnum;
import springbook.model.Result;

@ControllerAdvice
@ResponseBody
@Slf4j
public class ErrorAdvice {

    @ExceptionHandler(ArithmeticException.class)
    public Result handler1(ArithmeticException e) {
        //统一异常处理返回
        log.error("发送算术异常，Error：", e);
        return Result.fail("发生算术"+e.getMessage());
    }
    @ExceptionHandler(NullPointerException.class)
    public Result handler2(NullPointerException e) {
        //统一异常处理返回
        log.error("发送空指针异常，Error：", e);
        return Result.fail("发送空指针异常"+e.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public Result handler3(Exception e) {
        //统一异常处理返回
        log.error("发送异常，Error：", e);
        return Result.fail("发生异常"+e.getMessage());
    }
}
